package com.fm.financemanage.service;

import com.fm.financemanage.mapper.SimCardMapper;
import com.fm.financemanage.mapper.SmsNoticeRecordMapper;
import com.fm.financemanage.model.po.Accountant;
import com.fm.financemanage.model.po.SimCard;
import com.fm.financemanage.model.vo.PageVo;
import com.fm.financemanage.model.vo.accountant.AccountantListVo;
import com.fm.financemanage.model.vo.accountant.AccountantOperatorVo;
import com.fm.financemanage.model.vo.simcard.SimCardListVo;
import com.fm.financemanage.model.vo.simcard.SimCardNoticeListVo;
import com.fm.financemanage.model.vo.simcard.SimCardOpeartorVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@Service
public class SimCardService {

    @Resource
    private SimCardMapper simCardMapper;
    @Resource
    private SmsNoticeRecordMapper smsNoticeRecordMapper;

    public PageVo<List<SimCardListVo>> getList(String uuid, String sinCardNumber, Integer accountantId, Integer page, Integer limit) {

        return new PageVo<List<SimCardListVo>>(simCardMapper.getList(null,uuid, sinCardNumber, accountantId, (page - 1) * limit, limit),
                simCardMapper.count(null,uuid, sinCardNumber, accountantId));

    }


    public void operator(SimCardOpeartorVo simCardOpeartorVo) {
        final SimCard simCard = new SimCard();
        BeanUtils.copyProperties(simCardOpeartorVo, simCard);
        if (simCard.getId() == null) {
            simCard.setUuid(UUID.randomUUID().toString().replace("-", ""));
            simCard.setCreateTime(LocalDateTime.now());
            simCard.setUpdateTime(LocalDateTime.now());
            simCardMapper.insertSelective(simCard);
        } else {
            simCard.setUpdateTime(LocalDateTime.now());
            simCardMapper.updateByPrimaryKeySelective(simCard);
        }
    }


    public void removeById(Integer id) {
        simCardMapper.deleteByPrimaryKey(id);
    }

    public PageVo<List<SimCardNoticeListVo>> getNoticeRecordList(String uuid, Integer simCardId, Integer accountantId, Integer page, Integer limit) {
        return new PageVo<List<SimCardNoticeListVo>>(smsNoticeRecordMapper.getList(null,uuid, simCardId, accountantId, (page - 1) * limit, limit),
                smsNoticeRecordMapper.count(null,uuid, simCardId, accountantId));
    }

    public void removeNotice(Integer id) {
        smsNoticeRecordMapper.deleteByPrimaryKey(id);
    }


}
